/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-21
 * Time: 22:15
 */
//https://leetcode.cn/problems/peak-index-in-a-mountain-array/
public class Test {
    public static int peakIndexInMountainArray(int[] arr) {
        int p1=1,p2=arr.length-2;
        int p=(p1+p2)/2;
        while(p1<=p2){
            if(arr[p-1]<arr[p]&&arr[p]>arr[p+1]){
                return p;
            }
            if(arr[p]>arr[p-1]){
                p1=p+1;
            }
            else{
                p2=p-1;
            }
            p=(p1+p2)/2;
        }
        return p;
    }
    public static void main(String[] args) {
        int[] arr={3,4,5,1};
        System.out.println(peakIndexInMountainArray(arr));
    }
}
